﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FacialClub.Helpers
{
    /// <summary>
    /// List Extensions
    /// </summary>
    public static class ListExtensions
    {
        /// <summary>
        /// ForEach
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="action"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static IEnumerable<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action)
        {
            foreach (var item in collection) action(item);
            return collection;
        }

        /// <summary>
        /// To Select List
        /// </summary>
        /// <param name="collection"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SelectList ToSelectList<T>(this IEnumerable<T> collection)
        {
            return new SelectList(collection, "Key", "Value");
        }

        /// <summary>
        /// To Select List
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="selectedValue"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SelectList ToSelectList<T>(this IEnumerable<T> collection, string selectedValue)
        {
            return new SelectList(collection, "Key", "Value", selectedValue);
        }

        /// <summary>
        /// To Select List
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="dataValueField"></param>
        /// <param name="dataTextField"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SelectList ToSelectList<T>(this IEnumerable<T> collection,
                             string dataValueField, string dataTextField)
        {
            return new SelectList(collection, dataValueField, dataTextField);
        }

        /// <summary>
        /// To Select List
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="dataValueField"></param>
        /// <param name="dataTextField"></param>
        /// <param name="selectedValue"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static SelectList ToSelectList<T>(this IEnumerable<T> collection,
                             string dataValueField, string dataTextField, string selectedValue)
        {
            return new SelectList(collection, dataValueField, dataTextField, selectedValue);
        }

    }
}